from django.db import models
from django.contrib.auth.models import User
import datetime
from django.utils import timezone
from taggit.managers import TaggableManager


class Event(models.Model):
  STATUS_CHOICES = (
      ('A', 'Active'),
      ('S', 'Suspended'),
      ('C', 'Closed')
      )
  name = models.CharField(max_length=200)
  description = models.CharField(max_length=2000)
  status = models.CharField(max_length=1, choices=STATUS_CHOICES)
  #start_time = ...
  end_time = models.DateTimeField(default=(timezone.now() + datetime.timedelta(days=10)))
  tags = TaggableManager()


class Order(models.Model):
  TYPE_CHOICES = (
      ('B', 'Buy'),
      ('S', 'Sell')
      )
  # Refer to Fidelity. https://scs.fidelity.com/webxpress/help/topics/help_definition_s.shtml#status
  STATUS_CHOICES = (
      ('O', 'Open'),
      ('C', 'Canceled'),
      ('F', 'Filled'),
      ('P', 'Partially Filled')
      )

  user = models.ForeignKey(User)
  event = models.ForeignKey(Event)
  quantity = models.IntegerField()
  type = models.CharField(max_length=1, choices=TYPE_CHOICES)
  limit_price = models.DecimalField(decimal_places=2, max_digits=12)
  status = models.CharField(max_length=1, choices=STATUS_CHOICES)
  time_created = models.DateTimeField('date created')
  time_updated = models.DateTimeField('date updated')